package com.loveprogrammer.eternity.model.product;

import com.loveprogrammer.eternity.enums.QualityEnum;
import com.loveprogrammer.eternity.factory.EffectFactory;
import com.loveprogrammer.eternity.factory.template.EffectTemplate;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.effect.AbstractEffect;
import com.loveprogrammer.eternity.model.effect.Effect;
import com.loveprogrammer.eternity.skill.State;
import com.loveprogrammer.eternity.utils.Util;

import java.io.Serializable;
import java.util.*;

/**
 * @version 1.0.0
 * @description:
 * @author: eric
 * @date: 2022-08-02 18:27
 **/
public abstract class Goods implements GoodsEffect, Serializable {

    private String id;

    private Integer goods_id = 0;

    private String name;

    private String type;

    private int level;

    private String desc;

    public  String string ="\t\t\t\t\t\t\t\t\t";

    // 品质
    public QualityEnum quality;

    // 毒抗
    private int poisonResistance;

    // 火抗
    private int flameResistance;

    // 电抗
    private int thunderResistance;

    // 冰抗
    private int iceResistance;

    // 效果id
    private List<GoodsEffectTemplate> effects;

    private Set<String> suffix;

    public Goods(){

    }

    // 没有等级的物品
    public Goods(String name, String type, String desc, QualityEnum quality, int goodsId) {
        this.name = name;
        this.type = type;
        this.desc = desc;
        this.quality = quality;
        this.goods_id = goodsId;
        this.id = Util.uuid();
    }

    // 有等级的物品
    public Goods(String name, String type, String desc, QualityEnum quality,int level,
                 int poisonResistance,int flameResistance,int thunderResistance,int iceResistance,
                List<GoodsEffectTemplate> effects,int goodsId) {
        this(name,type,desc,quality,goodsId);
        this.level = level;
        this.poisonResistance = poisonResistance;
        this.flameResistance = flameResistance;
        this.thunderResistance = thunderResistance;
        this.iceResistance = iceResistance;
        this.effects = effects;
    }

    // 物品打印信息的重写
    public String toString() {
        return  string+"****物品信息****\n"+
                string+"名称："+this.name+"\n"+
                string+"类型："+this.type +"\n"+
                string+"说明："+this.desc +"\n"+
                string+""+"***************";
    }

    // 物品打印信息的重写
    public String prettyPrint() {
        return  string+"****物品信息****\n"+
                string+"名称："+ this.name+"\n"+
                string+"品质："+ this.quality.getDesc() +"\n"+
                string+"说明："+ this.desc +"\n"+
                string+""+"***************";
    }

    @Override
    public List<State> states() {
        return new ArrayList<>();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public QualityEnum getQuality() {
        return quality;
    }

    public void setQuality(QualityEnum quality) {
        this.quality = quality;
    }

    public String getString() {
        return string;
    }

    public void setString(String string) {
        this.string = string;
    }

    public int getPoisonResistance() {
        return poisonResistance;
    }

    public void setPoisonResistance(int poisonResistance) {
        this.poisonResistance = poisonResistance;
    }

    public int getFlameResistance() {
        return flameResistance;
    }

    public void setFlameResistance(int flameResistance) {
        this.flameResistance = flameResistance;
    }

    public int getThunderResistance() {
        return thunderResistance;
    }

    public void setThunderResistance(int thunderResistance) {
        this.thunderResistance = thunderResistance;
    }

    public int getIceResistance() {
        return iceResistance;
    }

    public void setIceResistance(int iceResistance) {
        this.iceResistance = iceResistance;
    }

    public List<GoodsEffectTemplate> getEffects() {
        if(effects == null){
            effects = new ArrayList<>();
        }
        return effects;
    }

    public void setEffects(List<GoodsEffectTemplate> effects) {
        this.effects = effects;
    }

    public void gainSuffixEffects(List<EffectTemplate> effects) {
        List<GoodsEffectTemplate> list = getEffects();
        for (EffectTemplate effect : effects) {
            this.setName(name + "["+effect.getName()+"]");
            EffectTemplate template = EffectFactory.getTemplateById(effect.getId());
            list.add(new Goods.GoodsEffectTemplate(template));
        }
        setEffects(list);
    }

    public static class GoodsEffectTemplate implements Serializable{
        private String className;

        private List<Object> params;

        private String id;

        private String name;

        private Integer templateId;

        public GoodsEffectTemplate(String className, List<Object> params, String id, Integer templateId) {
            this.className = className;
            this.params = params;
            this.id = id;
            this.templateId = templateId;
        }

        public GoodsEffectTemplate(EffectTemplate template) {
            this.className = template.getClassName();
            this.params = template.getParams();
            this.id = UUID.randomUUID().toString();
            this.templateId = template.getId();
            this.name = template.getName();
        }

        public String getClassName() {
            return className;
        }

        public void setClassName(String className) {
            this.className = className;
        }

        public List<Object> getParams() {
            return params;
        }

        public void setParams(List<Object> params) {
            this.params = params;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public Integer getTemplateId() {
            return templateId;
        }

        public void setTemplateId(Integer templateId) {
            this.templateId = templateId;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    public Set<String> getSuffix() {
        if(suffix == null){
            suffix = new HashSet<>();
        }
        return suffix;
    }

    public void setSuffix(Set<String> suffix) {
        this.suffix = suffix;
    }

    public void addSuffix(String suffix) {
        Set<String> sufSet = getSuffix();
        sufSet.add(suffix);
        this.suffix = sufSet;
    }

    public Integer getGoods_id() {
        return goods_id;
    }

    public void setGoods_id(Integer goods_id) {
        this.goods_id = goods_id;
    }
}
